//
//  MCGameRecordMineFilterView.m
//  TLYL
//
//  Created by miaocai on 2017/7/11.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCGameRecordMineFilterView.h"

@interface MCGameRecordMineFilterView ()

@property (nonatomic,weak) UIButton *recordBtn;
@property (nonatomic,weak) UIButton *startTimeBtn;
@property (nonatomic,weak) UIButton *endTimeBtn;
@property (nonatomic,weak) UIView *lineView1;
@property (nonatomic,weak) UIView *lineView2;
@property (nonatomic,weak) UIView *lineView3;
@property (nonatomic,weak) UILabel *totalLabel;
@property (nonatomic,weak) UIView *lineView;
@property (nonatomic,weak) UIView *topView;

@end

@implementation MCGameRecordMineFilterView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, G_SCREENWIDTH, 44)];
    [self addSubview:topView];
    self.topView = topView;
    NSArray *titleArray = @[@"全部",@"待开奖",@"已中奖",@"未中奖"];
    
    for (NSInteger i = 0; i<titleArray.count; i++) {
        UIButton *btn = [[UIButton alloc] init];
        [topView addSubview:btn];
        btn.frame = CGRectMake(i * 0.25 * G_SCREENWIDTH, 0, 0.25 * G_SCREENWIDTH, 42);
        [btn setTitle:titleArray[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
        btn.tag = i + 1000;
        if (btn.tag == 1000) {
            btn.selected = YES;
        }else{
            btn.selected = NO;
        }
        
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    }
    UIView *lineView0 = [[UIView alloc] initWithFrame:CGRectMake(0, 43, G_SCREENWIDTH, 1)];
    lineView0.backgroundColor = [UIColor darkGrayColor];
    [topView addSubview:lineView0];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 42, 60, 2)];
    [topView addSubview:lineView];
    lineView.backgroundColor = [UIColor blueColor];
    self.lineView = lineView;
    UIButton *recordBtn = [[UIButton alloc] init];
    [self addSubview:recordBtn];
    self.recordBtn = recordBtn;
    [recordBtn setTitle:@"当前记录" forState:UIControlStateNormal];
    [recordBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    recordBtn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    
    UIButton *startTimeBtn= [[UIButton alloc] init];
    [self addSubview:startTimeBtn];
    self.startTimeBtn = startTimeBtn;
    [startTimeBtn setTitle:@"2017-55-05" forState:UIControlStateNormal];
    [startTimeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    startTimeBtn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    
    UIButton *endTimeBtn = [[UIButton alloc] init];
    [self addSubview:endTimeBtn];
    self.endTimeBtn = endTimeBtn;
    [endTimeBtn setTitle:@"2017-05-06" forState:UIControlStateNormal];
    [endTimeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    endTimeBtn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    UIView *lineView1 = [[UIView alloc] init];
    [self addSubview:lineView1];
    lineView1.backgroundColor = [UIColor darkGrayColor];
    self.lineView1 = lineView1;
    UIView *lineView2 = [[UIView alloc] init];
    [self addSubview:lineView2];
    lineView2.backgroundColor = [UIColor darkGrayColor];
    self.lineView2 = lineView2;
    UIView *lineView3 = [[UIView alloc] init];
    [self addSubview:lineView3];
    self.lineView3 = lineView3;
    lineView3.backgroundColor = [UIColor darkGrayColor];
    UILabel *totalLabel = [[UILabel alloc] init];
    [self addSubview:totalLabel];
    self.totalLabel = totalLabel;
    self.totalLabel.text = @"记录总署：3333条";
    self.totalLabel.font = [UIFont systemFontOfSize:12];
    self.totalLabel.textAlignment = NSTextAlignmentCenter;
    self.totalLabel.textColor = [UIColor darkGrayColor];
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    [self.recordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(44);
        make.width.equalTo(@(G_SCREENWIDTH/3));
        make.height.equalTo(@(44));
        make.left.equalTo(self);
    }];
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.recordBtn.mas_right);
        make.top.equalTo(self).offset(46);
        make.height.equalTo(@(40));
        make.width.equalTo(@(1));
    }];
    [self.startTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(44);
        make.width.equalTo(@(G_SCREENWIDTH/3-1));
        make.left.equalTo(self.lineView1.mas_right);
        make.height.equalTo(@(44));
    }];
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.startTimeBtn.mas_right);
        make.top.equalTo(self).offset(46);
        make.width.equalTo(@(1));
        make.height.equalTo(@(40));
    }];
    [self.endTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(44);
        make.width.equalTo(@(G_SCREENWIDTH/3 -1));
        make.right.equalTo(self);
        make.height.equalTo(@(44));
    }];
    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(2);
        make.top.equalTo(self.startTimeBtn.mas_bottom);
        make.right.equalTo(self).offset(-2);
        make.height.equalTo(@(1));
    }];
    
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView3.mas_bottom);
        make.left.right.equalTo(self);
        make.height.equalTo(@(MC_REALVALUE(20)));
    }];
}
- (void)changeBtnStatus:(int)index{

    for (UIView *view in self.topView.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            UIButton *btn1 = (UIButton *)view;
            if (btn1.tag - 1000 == index) {
                btn1.selected = YES;
                [UIView animateWithDuration:0.25 animations:^{
                    self.lineView.size = CGSizeMake(60, 2);
                    self.lineView.center = CGPointMake(btn1.centerX, 43);
                }];
            } else {
                btn1.selected = NO;
            }
            
        }
    }
 

}
- (void)btnClick:(UIButton *)btn{
     btn.selected = !btn.selected;
    for (UIView *view in self.topView.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            UIButton *btn1 = (UIButton *)view;
            if (btn == btn1) {
                btn.selected = NO;
            }else{
                btn1.selected = YES;
            }
        }
    }
    [UIView animateWithDuration:0.25 animations:^{
        self.lineView.size = CGSizeMake(60, 2);
        self.lineView.center = CGPointMake(btn.centerX, 43);
    }];
    int index = (int)btn.tag - 1000;
    if (self.gameRecFilterBtnClickBlock) {
        self.gameRecFilterBtnClickBlock(index);
    }
}
@end
